import axios, { AxiosRequestConfig } from 'axios'

import {
  IAddressInfoReq,
  IAddressInfoRes,
  IBatchSetRes,
  ISetBatchPublishEventReq,
  ISetBatchPublishFirstLegInformationReq,
  ISetBatchPublishLastLegInformationReq,
  ISetBatchPublishLogisticsChannelReq,
  IWaybillRecordListReq,
  IWaybillRecordListRes,
  IWaybillRecordTabCountRes,
} from '../interface'
import './__mock__'

/** 获取运单列表 */
export const apiWaybillRecordList = async (
  req: IWaybillRecordListReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<IWaybillRecordListRes> => {
  return axios.post(`/tmsapi/waybill_record_v2/list`, { ...req }, { signal }).then(res => ({
    ...res.$data,
  }))
}

/** 获取运单页签数据 */
export const apiWaybillRecordTabCount = async (
  req: IWaybillRecordListReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<IWaybillRecordTabCountRes> => {
  return axios.post(`/tmsapi/waybill_record_v2/tab/count`, { ...req }, { signal }).then(res => res.$data)
}

/** 批量设置发布事件 */
export const apiBatchSetPublishEvent = async (
  req: ISetBatchPublishEventReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<IBatchSetRes> => {
  return axios.post(`/tmsapi/waybill_record_v2/batch/set/publish_event`, req, { signal }).then(res => res.$data)
}

/** 批量设置物流渠道 */
export const apiBatchSetLogisticsChannel = async (
  req: ISetBatchPublishLogisticsChannelReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<IBatchSetRes> => {
  return axios.post(`/tmsapi/waybill_record_v2/batch/set/logistics_channel`, req, { signal }).then(res => res.$data)
}

/** 批量设置第一程信息 */
export const apiBatchSetFirstLegInformation = async (
  req: ISetBatchPublishFirstLegInformationReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<IBatchSetRes> => {
  return axios.post(`/tmsapi/waybill_record_v2/batch/set/first_leg_information`, req, { signal }).then(res => res.$data)
}

/** 批量设置最后程信息 */
export const apiBatchSetLastLegInformation = async (
  req: ISetBatchPublishLastLegInformationReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<IBatchSetRes> => {
  return axios.post(`/tmsapi/waybill_record_v2/batch/set/last_mile`, req, { signal }).then(res => res.$data)
}

/** 批量获取运单地址信息 */
export const apiWaybillRecordAddressInfo = async (
  req: IAddressInfoReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<IAddressInfoRes[]> => {
  return axios.post(`/tmsapi/waybill_record_v2/addressInfo`, req, { signal }).then(res => res.$data)
}
